
function value2Camp(value) {
	switch(value) {
		case 0: return "none";
		case 1: return "black";
		case 2: return "white";
	}
}

function autologin() {
	$.ajax({
		url:"autolog.user",
		type:"post",
		dataType:"json",
		success:function(data) {
			responseProcess(data);
		}
	});
}

function accountStrTest(acc) {
    return new RegExp("^([^<>/\"'$]){6,16}$").test(acc);
}

function nickTest(id) {
    return new RegExp("^([^<>/\"'$]){0,16}$").test(id);
}

function projectRootDir(path) {
	if(path == null  ||  path == "") return "";
	var start = 0, len = path.length, i, j;
	if(path.charAt(0) == "/") {
		++start;
	}
	for(i = start, j = 0; i < len; ++i, ++j) {
		if(path.charAt(i) == "/") break;
	}
	return path.substr(start, j);
}

function defaultPlayerHeadPic() {
	return "url(\"" + 
				location.protocol + "//" +  
				location.hostname + ":" +
				location.port + "/" +
				projectRootDir(location.pathname) + 
				"/img/defaultPlayerHeadPic.png" +
			"\")";
}

function headPicPathname(headPicFile) {
	if(headPicFile == null || headPicFile == "" || headPicFile == "default") 
		return defaultPlayerHeadPic();
	
	return "url(\"" + 
				location.protocol + "//" +  
				location.hostname + ":" +
				location.port + "/" +
				projectRootDir(location.pathname) + 
				"/data/z5col/z5col_files/pictures/" +
				headPicFile +
			"\")";
}

function ztaLogoPathname() {
	 return "url(\"" + 
				location.protocol + "//" +  
				location.hostname + ":" +
				location.port + "/" +
				projectRootDir(location.pathname) + 
				"/favicon.ico" + 
			"\")";
}

function responseProcess(json) {
    switch(json.type) {
        case "loginSuccess":
        case "registSuccess":
        case "redirect":
        case "logOut":
            location.href = json.redirect;
			return true;
		case "joinedRoom":
			alert(";) 请先退出已进入的房间再来喔～");
			return true;
			break;
        case "loginFail":
            $("#loginFailTip").removeClass("hid");
            break;
        case "cookieLoginFail":
            break;
        case "registFail":
            $("#registFailTip").removeClass("hid");
            break;
    }
	return false;
}

function goPage(page) {
	location.href =
		location.protocol + "//" +  
		location.hostname + ":" +
		location.port + "/" +
		projectRootDir(location.pathname) + 
		page;
}

function goHome() {
	goPage("/Hall.html");
}

function goUserPage() {
	goPage("/userPage.html");
}

function goBattleRoom() {
	goPage("/battle.html");
}

function goRank() {
	goPage("/rank.html");
}

function refresh() {
	location.reload();
}